package com.Ian.homework;

import java.util.HashMap;

public class HashMapCounter {

    public static void printHashMap(HashMap<String, Integer> hsm) {
        for (String s : hsm.keySet()
        ) {
            System.out.println("数字字符串" + s + "出现的次数" + hsm.get(s));
        }

    }

    public static void saveHashMap(String[] strs) {
        HashMap<String, Integer> datas = new HashMap<>();
        for (String s : strs
        ) {
            String strKey = s;
            Integer iValue = datas.get(strKey);
            if (iValue == null) {
                datas.put(strKey, 1);
            } else {
                datas.put(strKey, ++iValue);
            }
        }
        printHashMap(datas);
    }

    public static void main(String[] args) {
        String[] strDData = {"111", "222", "211", "123", "123", "111", "222"};
        saveHashMap(strDData);
    }
}
